/**
 * Created By zhangQ 2018/3/1
 * 1.自动计算高度
 */
export default {
  getFullHeight (objId, balance) {
    if (objId) {
      let obj = document.getElementById(objId)
      if (obj) {
        let wh = window.innerHeight || (document.documentElement && document.documentElement.clientHeight) ||
          document.body.clientHeight
        if (!balance && balance !== 0) {
          balance = 0
        }
        return wh - obj.offsetTop - balance
      }
    }
  },
  setFullHeightAllWith (objId, balance, next) {
    window.addEventListener('resize', () => {
      next(this.getFullHeight(objId, balance))
    })
    next(this.getFullHeight(objId, balance))
  },
  setResizeByIdAndHeight (id, height) {
    let wh = window.innerHeight || (document.documentElement && document.documentElement.clientHeight) ||
      document.body.clientHeight
    let vid = document.getElementById(id)
    if (vid) {
      vid.style.height = (wh - vid.offsetTop - height) + 'px'
    }
  },
  setResizeToResizeHeight (id, height, next) {
    window.addEventListener('resize', () => {
      this.setResizeByIdAndHeight(id, height)
    })
    if (next && typeof next === 'function') {
      setTimeout(() => {
        this.setResizeByIdAndHeight(id, height)
        next()
      }, 300)
    } else {
      this.setResizeByIdAndHeight(id, height)
    }
  }
}
